package com.idanchuang.component.businesslog.es.index;

import org.elasticsearch.client.*;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.Set;

/**
 * The CustomRestHighLevelClient
 *
 * @since 2020/7/17
 */
public class CustomRestHighLevelClient extends RestHighLevelClient {

    private final IndexManageClient indexManageClient = new IndexManageClient(this);

    public CustomRestHighLevelClient(RestClientBuilder restClientBuilder) {
        super(restClientBuilder);
    }

    public IndexManageClient indexManage() {
        return indexManageClient;
    }

    public <Req extends Validatable, Resp> Resp performRequestAndParseEntityCustom(Req request,
                                                                                   CheckedFunction<Req, Request, IOException> requestConverter,
                                                                                   RequestOptions options,
                                                                                   CheckedFunction<XContentParser, Resp, IOException> entityParser,
                                                                                   Set<Integer> ignores) throws IOException {
        return performRequest(request, requestConverter, options,
                response -> parseEntity(response.getEntity(), entityParser), ignores);
    }
}
